﻿Imports System.Data.OleDb

Public Class addHotel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnAddHotel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddHotel.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"
        If f_Picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("Pictures") & "/" & newFileName
            f_Picture.SaveAs(picLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("HotelsConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into Hotels(HotelName,Stars,Location,Description,HotelUrl,Pictures) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtHotelName.Text)
        cmd.Parameters.AddWithValue("@f2", rbl_Stars.SelectedValue)
        cmd.Parameters.AddWithValue("@f3", txtLocation.Text)
        cmd.Parameters.AddWithValue("@f4", txtDescription.Text)
        cmd.Parameters.AddWithValue("@f5", txtHotelUrl.Text)
        cmd.Parameters.AddWithValue("@f6", "Pictures/" & newFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rbl_Stars.SelectedIndexChanged

    End Sub
End Class